package dormouse.vfs.ui;

/**
 * <p>Title: Ammonite</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2001</p>
 * <p>Company: Kymerix</p>
 * @author Mark Fortner
 * @version 1.0
 */
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;
import javax.swing.JTree;
public class FileNodeEditor extends AbstractCellEditor {
	FileNodeEditorRenderer renderer;
	FileNode lastEditedNode;
	JCheckBox checkBox;

	public FileNodeEditor() {
		renderer = new FileNodeEditorRenderer();
		checkBox = renderer.getCheckBox();

		checkBox.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lastEditedNode.setSelected(checkBox.isSelected());
				stopCellEditing();
			}
		});
	}
	public Component getTreeCellEditorComponent(
						JTree tree, Object value,
						boolean selected, boolean expanded,
						boolean leaf, int row) {
		lastEditedNode = (FileNode)value;

		return renderer.getTreeCellRendererComponent(tree,
							value, selected, expanded,
							leaf, row, true); // hasFocus ignored
	}
	public Object getCellEditorValue() {
		return lastEditedNode.getUserObject();
	}
}